//
//  StatuCell.swift
//  
//
//  Created by gongjunna on 15/8/1.
//
//

import UIKit

class StatuCell: UITableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    var pictureH : NSLayoutConstraint?
    var pictureW : NSLayoutConstraint?
    var statu : Statu? {
    didSet {
        footView.status = statu
        labView.text = statu?.text
        pictureView.status = statu
        pictureH?.constant = pictureView.bounds.height
        pictureW?.constant = pictureView.bounds.width
    }
}
    
//    override func setSelected(selected: Bool, animated: Bool) {
//        super.setSelected(selected, animated: animated)
//
//        // Configure the view for the selected state
//    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        prepareUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func prepareUI() {
    
        contentView.addSubview(footView)
        contentView.addSubview(labView)
        contentView.addSubview(pictureView)
        contentView.addSubview(bottomView)
        // foot View
        footView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: contentView, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 70), offset: CGPoint.zeroPoint)
        // MARK: - labView
        labView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: footView, size:nil , offset: CGPoint(x: 8, y: 0))
        contentView.addConstraint(NSLayoutConstraint(item: labView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.Width, multiplier: 1.0, constant: -16))
        // MARK: -  pictureView 
       let con =  pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: labView, size: CGSize(width: 170, height: 170))
       
        pictureH = pictureView.ff_Constraint(con , attribute: NSLayoutAttribute.Height)
        pictureW = pictureView.ff_Constraint(con, attribute: NSLayoutAttribute.Width)
        
        
        // MARK: - bottomView
        bottomView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: pictureView, size: nil, offset: CGPoint(x: 0, y: 0))
        contentView.addConstraint(NSLayoutConstraint(item: bottomView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.Width, multiplier: 1.0, constant: 0))
    
    }
    lazy  var footView : FootView = FootView()
    lazy var labView : UILabel = {
        let  lb  = UILabel()
        lb.numberOfLines = 0
        return lb
        }()
    lazy var pictureView : PictureCollectionView = PictureCollectionView()

    lazy  var bottomView : BottomView = BottomView()
    
}
